﻿Imports CommonLayer
Imports DataAccessLayer

Public Class BLSecurity
    Inherits BLBase

#Region "Declaration"

    Private m_strForeignKey As String
    'Private Const mscSQLExceptionContrainsNumber As Integer = 547
    'Private Const mscSQLExceptionConcurrence As String = "Row ban xoa khong ton tai"
    Private oDLSecurity As DLSecurity

#End Region

#Region "Property"

    Public Property ForeignKey() As String
        Get
            Return m_strForeignKey
        End Get
        Set(ByVal value As String)
            m_strForeignKey = value
        End Set
    End Property

#End Region

#Region "Constructor"

#End Region

#Region "Get Method"

    Public Sub GetPermissionList_ByActorID(ByRef table As DataTable, ByVal ParamArray oPara As Object())
        Try
            table.Clear()
            oDLSecurity.GetPermissionList_ByActorID(table, oPara)
        Catch ex As Exception
            Throw
        End Try
    End Sub

    Public Function CheckPermissionByActor(ByVal ParamArray oPara As Object()) As Boolean
        Try
            Return oDLSecurity.CheckPermissionByActor(oPara)
        Catch ex As Exception
            Throw
        End Try
    End Function


    Public Shared Function CheckLogIn(ByVal sConnectionString As String, ByVal strUser As String, _
                                      ByVal encryptPass As String) As Integer
        Try
            Return DLSecurity.CheckLogIn(sConnectionString, strUser, encryptPass)
        Catch ex As Exception
            Throw

        End Try
    End Function

#End Region

#Region "CRUD"

#Region "InitNewRow"

    Public Function AddNewUser(Optional ByVal strID As Object = Nothing) As DataRow
        Dim dr As DataSetPermission.SYSUserRow = Nothing
        dr = dtBusiness.NewRow
        With dr
            .UserName = ""
            .Password = ""
            .FullName = ""
            .Inactive = False
            .IsSystem = False
            .IsOnline = False
        End With
        dtBusiness.Rows.InsertAt(dr, 0)
        Return dr
    End Function

    Public Function AddNewGroup(Optional ByVal strID As Object = Nothing) As DataRow
        Dim dr As DataSetPermission.SYSGroupUserRow = Nothing
        dr = dtBusiness.NewRow
        With dr
            .GroupID = IIf(strID IsNot Nothing, strID, Guid.NewGuid)
            .GroupName = ""
            .Inactive = False
            .IsSystem = False
        End With
        dtBusiness.Rows.InsertAt(dr, 0)
        Return dr
    End Function


#End Region

#End Region

#Region "Private Method"

#End Region

#Region "Other Method"

    Public Overrides Sub InitPublicObject()
        oDLBase = New DLSecurity(BLCommonFactory.DatabaseConnectName)
        oDLSecurity = oDLBase
    End Sub

#End Region
End Class
